package com.eastfair.transport.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.transport.dto.BindServiceProviderRoleDTO;
import com.eastfair.transport.dto.RemoveServiceProviderRoleDTO;
import com.eastfair.transport.service.TransportRegisterService;
import com.eastfair.transport.vo.TransportRegisterDataVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * 主场服务用户注册
 * </p>
 *
 * @author lyw
 * @date 2022 -08-10
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/transportRegister")
public class TransportRegisterController {

    @Autowired
    private TransportRegisterService transportRegisterService;


    /**
     * 主场服务商注册
     *
     * @param userAccountDto 用户新增实体
     * @return r
     */
    @ApiOperation(value = "主场服务商注册", notes = "主场服务商注册")
    @SysLog("主运服务商注册")
    @PostMapping("/registerUser")
    public R<TransportRegisterDataVO> registerUser(@RequestBody UserAccountDto userAccountDto) {
        try {
            return R.success(transportRegisterService.registerHomeUser(userAccountDto));
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 主场服务商绑定角色.
     *
     * @param bindHomeServiceProviderRoleDTO the bind home service provider role dto
     * @return r
     */
    @PostMapping("/bind/role")
    public R<Boolean> bindServiceProviderRole(@RequestBody BindServiceProviderRoleDTO bindHomeServiceProviderRoleDTO) {
        try {
            return R.success(transportRegisterService.bindHomeServiceProviderRole(bindHomeServiceProviderRoleDTO));
        } catch (BizException e) {
            return R.fail(e);
        }
    }


    /**
     * 主场服务商移除角色
     *
     * @param removeHomeServiceProviderRoleDTOList the remove home service provider role dto list
     * @return r
     */
    @PostMapping("/remove/role")
    public R<Boolean> removeServiceProviderRole(@RequestBody List<RemoveServiceProviderRoleDTO> removeHomeServiceProviderRoleDTOList) {
        try {
            return R.success(transportRegisterService.removeHomeServiceProviderRole(removeHomeServiceProviderRoleDTOList));
        } catch (BizException e) {
            return R.fail(e);
        }
    }
}
